From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 11:13:19 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 13 15:13:51 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Jan 13 15:13:51 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 13 15:13:51 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 13 15:13:51 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 15:13:51 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 13 15:13:51 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 15:13:51 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 13 15:13:51 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 15:13:51 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 15:13:52 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 13 15:13:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 15:13:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 13 15:13:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 13 15:13:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 15:13:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 13 15:13:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Jan 13 15:13:52 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0001.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 15:13:52 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 13 15:13:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 13 15:13:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 13 15:13:52 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 15:13:52 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0002.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 15:21:14 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 13 16:00:46 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0003.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 16:00:47 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 13 20:01:35 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0004.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 13 20:01:36 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0005.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 08:02:18 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 14 12:00:43 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Jan 14 12:00:43 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 14 12:00:43 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 14 12:00:43 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 12:00:43 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 14 12:00:43 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 12:00:43 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 14 12:00:43 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 12:00:43 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 12:00:43 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 14 12:00:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 12:00:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 14 12:00:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 14 12:00:44 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 12:00:44 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 14 12:00:44 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Jan 14 12:00:44 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0006.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 12:00:44 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 14 12:00:44 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 14 12:00:44 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 14 12:00:44 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 12:00:44 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0007.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 16:00:43 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0008.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 14 20:00:41 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 15 08:02:05 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Jan 15 08:02:05 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 15 08:02:05 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 15 08:02:05 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 08:02:05 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 15 08:02:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 08:02:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 15 08:02:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 08:02:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 08:02:05 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 15 08:02:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 08:02:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 15 08:02:06 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 15 08:02:06 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 08:02:06 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 15 08:02:06 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Jan 15 08:02:06 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0009.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 08:02:06 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 15 08:02:06 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 15 08:02:06 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 15 08:02:06 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 08:02:06 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 15 12:00:49 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Jan 15 12:00:49 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 15 12:00:49 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 15 12:00:49 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 12:00:49 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 15 12:00:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 12:00:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 15 12:00:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 12:00:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 12:00:49 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 15 12:00:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 12:00:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 15 12:00:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 15 12:00:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 12:00:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 15 12:00:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Jan 15 12:00:49 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0010.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 12:00:50 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 15 12:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 15 12:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 15 12:00:50 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 12:00:50 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 15 16:00:42 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Jan 15 16:00:42 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 15 16:00:42 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 15 16:00:42 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 16:00:42 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 15 16:00:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 16:00:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 15 16:00:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 16:00:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 16:00:42 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 15 16:00:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 16:00:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 15 16:00:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 15 16:00:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 16:00:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 15 16:00:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Jan 15 16:00:43 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0011.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 16:00:43 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 15 16:00:43 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 15 16:00:43 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 15 16:00:43 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 16:00:43 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0012.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 15 20:00:39 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0013.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 08:02:28 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0014.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 12:00:47 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 16 16:00:46 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Jan 16 16:00:46 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 16 16:00:46 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 16 16:00:46 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 16:00:46 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 16 16:00:46 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 16:00:46 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 16 16:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 16:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 16:00:47 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 16 16:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 16:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 16 16:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 16 16:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 16:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 16 16:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Jan 16 16:00:47 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0015.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 16:00:47 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 16 16:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 16 16:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 16 16:00:47 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 16:00:47 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0016.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 16 20:00:42 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0017.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 08:02:30 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 17 12:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Jan 17 12:00:59 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 17 12:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 17 12:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 12:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 17 12:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 12:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 17 12:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 12:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 12:00:59 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 17 12:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 12:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 17 12:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 17 12:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 12:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 17 12:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Jan 17 12:01:00 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0018.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 12:01:00 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 17 12:01:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 17 12:01:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 17 12:01:00 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 12:01:00 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 17 16:00:47 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Jan 17 16:00:47 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 17 16:00:47 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 17 16:00:47 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 16:00:47 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 17 16:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 16:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 17 16:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 16:00:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 16:00:47 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 17 16:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 16:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 17 16:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 17 16:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 16:00:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 17 16:00:48 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Jan 17 16:00:48 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0019.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 16:00:48 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 17 16:00:48 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 17 16:00:48 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 17 16:00:48 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 16:00:48 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0020.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 17 20:00:50 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0021.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 08:04:14 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0022.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 12:01:00 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0023.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 16:01:25 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 18 20:00:51 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Jan 18 20:00:51 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 18 20:00:51 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 18 20:00:52 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 20:00:52 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 18 20:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 20:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 18 20:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 20:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 20:00:52 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 18 20:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 20:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 18 20:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 18 20:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 20:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 18 20:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Jan 18 20:00:52 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0024.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 20:00:52 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 18 20:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 18 20:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 18 20:00:52 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 18 20:00:52 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0025.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 08:04:34 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0026.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 12:00:58 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 19 16:02:47 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Thu Jan 19 16:02:47 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 19 16:02:47 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 19 16:02:48 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 16:02:48 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 19 16:02:48 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 16:02:48 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 19 16:02:48 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 16:02:48 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 16:02:48 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 19 16:02:48 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 16:02:48 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 19 16:02:48 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 19 16:02:48 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 16:02:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 19 16:02:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Thu Jan 19 16:02:49 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0027.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 16:02:49 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 19 16:02:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 19 16:02:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 19 16:02:49 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 16:02:49 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0028.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 19 20:00:45 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 19 20:00:46 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 20 08:06:35 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Jan 20 08:06:36 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 20 08:06:36 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 20 08:06:36 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 08:06:36 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 20 08:06:36 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 08:06:36 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 20 08:06:37 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 08:06:37 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 08:06:37 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 20 08:06:37 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 08:06:37 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 20 08:06:37 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 20 08:06:37 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 08:06:37 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 20 08:06:37 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Jan 20 08:06:37 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0029.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 08:06:37 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 20 08:06:37 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 20 08:06:38 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 20 08:06:38 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 08:06:38 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 20 12:01:57 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Jan 20 12:01:58 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 20 12:01:58 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 20 12:01:58 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 12:01:58 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 20 12:01:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 12:01:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 20 12:01:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 12:01:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 12:01:58 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 20 12:01:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 12:01:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 20 12:01:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 20 12:01:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 12:01:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 20 12:01:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Jan 20 12:01:58 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0030.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 12:01:58 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 20 12:01:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 20 12:01:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 20 12:01:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 12:01:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0031.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 16:00:50 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0032.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 20 20:00:45 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0033.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 08:03:48 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 21 12:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Jan 21 12:00:59 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 21 12:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 21 12:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 12:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 21 12:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 12:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 21 12:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 12:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 12:00:59 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 21 12:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 12:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 21 12:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 21 12:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 12:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 21 12:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Jan 21 12:01:00 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0034.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 12:01:00 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 21 12:01:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 21 12:01:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 21 12:01:00 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 12:01:00 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0035.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 16:00:50 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0036.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 21 20:00:49 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0037.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 22 08:02:42 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 08:02:43 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0038.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 12:00:49 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 22 16:01:17 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Jan 22 16:01:17 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 22 16:01:17 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 22 16:01:17 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 16:01:17 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 22 16:01:17 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 16:01:17 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 22 16:01:17 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 16:01:17 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 16:01:17 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 22 16:01:17 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 16:01:17 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 22 16:01:17 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 22 16:01:17 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 16:01:18 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 22 16:01:18 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Jan 22 16:01:18 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0039.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 16:01:18 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 22 16:01:18 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 22 16:01:18 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 22 16:01:18 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 16:01:18 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0040.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 22 20:01:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 22 20:01:13 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 22 20:01:13 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0041.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 08:02:39 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 23 12:00:54 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Jan 23 12:00:54 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 23 12:00:54 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 23 12:00:54 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 12:00:54 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 23 12:00:54 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 12:00:54 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 23 12:00:54 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 12:00:54 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 12:00:54 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 23 12:00:54 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 12:00:54 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 23 12:00:54 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 23 12:00:54 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 12:00:54 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 23 12:00:54 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Jan 23 12:00:54 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0042.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 12:00:54 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 23 12:00:55 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 23 12:00:55 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 23 12:00:55 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 12:00:55 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 23 16:01:41 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Jan 23 16:01:41 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 23 16:01:41 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 23 16:01:41 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 16:01:41 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 23 16:01:41 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 16:01:41 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 23 16:01:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 16:01:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 16:01:42 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 23 16:01:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 16:01:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 23 16:01:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 23 16:01:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 16:01:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 23 16:01:42 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Jan 23 16:01:42 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0043.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 16:01:42 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 23 16:01:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 23 16:01:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 23 16:01:42 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 16:01:42 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 23 20:00:50 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Jan 23 20:00:50 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 23 20:00:50 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 23 20:00:50 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 20:00:50 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 23 20:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 20:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 23 20:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 20:00:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 20:00:50 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 23 20:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 20:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 23 20:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 23 20:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 20:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 23 20:00:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Jan 23 20:00:51 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0044.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 20:00:51 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 23 20:00:51 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 23 20:00:51 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 23 20:00:51 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 23 20:00:51 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0045.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 08:03:05 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 24 12:02:46 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Jan 24 12:02:46 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 24 12:02:46 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 24 12:02:46 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 12:02:47 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 24 12:02:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 12:02:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 24 12:02:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 12:02:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 12:02:47 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 24 12:02:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 12:02:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 24 12:02:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 24 12:02:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 12:02:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 24 12:02:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Jan 24 12:02:48 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0046.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 12:02:48 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 24 12:02:48 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 24 12:02:48 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 24 12:02:48 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 12:02:48 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 24 16:01:18 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Jan 24 16:01:18 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 24 16:01:18 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 24 16:01:18 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 16:01:18 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 24 16:01:18 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 16:01:18 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 24 16:01:18 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 16:01:18 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 16:01:18 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 24 16:01:18 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 16:01:18 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 24 16:01:18 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 24 16:01:18 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 16:01:18 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 24 16:01:18 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Jan 24 16:01:18 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0047.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 16:01:18 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 24 16:01:19 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 24 16:01:19 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 24 16:01:19 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 16:01:19 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 24 20:01:49 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Jan 24 20:01:49 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 24 20:01:49 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 24 20:01:49 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 20:01:49 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 24 20:01:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 20:01:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 24 20:01:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 20:01:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 20:01:49 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 24 20:01:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 20:01:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 24 20:01:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 24 20:01:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 20:01:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 24 20:01:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Jan 24 20:01:49 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0048.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 20:01:49 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 24 20:01:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 24 20:01:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 24 20:01:50 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 24 20:01:50 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0049.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 08:01:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0050.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 12:01:00 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0051.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 25 16:00:58 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 16:00:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0052.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Jan 25 20:00:52 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 26 08:05:28 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Thu Jan 26 08:05:30 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 26 08:05:30 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 26 08:05:30 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 08:05:30 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 26 08:05:31 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 08:05:31 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 26 08:05:31 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 08:05:31 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 08:05:31 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 26 08:05:31 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 08:05:31 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 26 08:05:32 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 26 08:05:32 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 08:05:32 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 26 08:05:32 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Thu Jan 26 08:05:32 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0053.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 08:05:32 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 26 08:05:32 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 26 08:05:32 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 26 08:05:32 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 08:05:32 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0054.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 12:01:04 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 26 16:00:51 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Thu Jan 26 16:00:51 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 26 16:00:51 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 26 16:00:51 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 16:00:51 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 26 16:00:51 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 16:00:51 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 26 16:00:51 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 16:00:51 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 16:00:52 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 26 16:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 16:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 26 16:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 26 16:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 16:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 26 16:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Thu Jan 26 16:00:52 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0055.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 16:00:52 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 26 16:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 26 16:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 26 16:00:52 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 16:00:52 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 26 20:00:45 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Thu Jan 26 20:00:45 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 26 20:00:45 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 26 20:00:45 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 20:00:45 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 26 20:00:45 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 20:00:45 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 26 20:00:45 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 20:00:45 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 20:00:45 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 26 20:00:45 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 20:00:46 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 26 20:00:46 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 26 20:00:46 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 20:00:46 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Jan 26 20:00:46 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Thu Jan 26 20:00:46 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0056.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 20:00:46 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Jan 26 20:00:46 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Jan 26 20:00:46 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Jan 26 20:00:46 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Jan 26 20:00:46 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 27 08:06:27 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Jan 27 08:06:28 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 27 08:06:28 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 27 08:06:28 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 08:06:28 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 27 08:06:28 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 08:06:28 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 27 08:06:28 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 08:06:28 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 08:06:28 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 27 08:06:28 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 08:06:28 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 27 08:06:28 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 27 08:06:28 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 08:06:28 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 27 08:06:28 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Jan 27 08:06:29 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0057.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 08:06:29 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 27 08:06:29 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 27 08:06:29 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 27 08:06:29 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 08:06:29 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0058.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 12:02:06 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 27 16:01:01 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Jan 27 16:01:01 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0059.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 16:01:02 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0060.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Jan 27 20:00:54 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 28 08:05:30 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Jan 28 08:05:30 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 28 08:05:30 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 28 08:05:30 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 08:05:30 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 28 08:05:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 08:05:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 28 08:05:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 08:05:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 08:05:30 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 28 08:05:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 08:05:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 28 08:05:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 28 08:05:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 08:05:31 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 28 08:05:31 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Jan 28 08:05:31 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0061.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 08:05:31 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 28 08:05:31 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 28 08:05:31 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 28 08:05:31 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 08:05:31 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0062.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 12:01:53 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0063.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 16:00:53 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0064.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Jan 28 20:00:52 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0065.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 29 08:07:25 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 29 08:07:26 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 08:07:26 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 29 12:00:58 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Jan 29 12:00:58 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 29 12:00:58 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 29 12:00:58 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 12:00:58 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 29 12:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 12:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 29 12:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 12:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 12:00:59 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 29 12:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 12:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 29 12:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 29 12:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 12:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 29 12:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Jan 29 12:00:59 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0066.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 12:00:59 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 29 12:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 29 12:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 29 12:00:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 12:00:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 29 16:00:52 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Jan 29 16:00:52 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 29 16:00:52 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 29 16:00:52 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 16:00:52 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 29 16:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 16:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 29 16:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 16:00:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 16:00:52 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 29 16:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 16:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 29 16:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 29 16:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 16:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 29 16:00:52 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Jan 29 16:00:53 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0067.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 16:00:53 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 29 16:00:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 29 16:00:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 29 16:00:53 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 16:00:53 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 29 20:00:53 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Jan 29 20:00:53 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 29 20:00:53 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 29 20:00:53 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 20:00:53 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 29 20:00:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 20:00:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 29 20:00:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 20:00:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 20:00:53 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 29 20:00:54 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 20:00:54 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 29 20:00:54 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 29 20:00:54 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 20:00:54 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Jan 29 20:00:54 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Jan 29 20:00:54 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0068.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 20:00:54 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Jan 29 20:00:54 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Jan 29 20:00:54 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Jan 29 20:00:54 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Jan 29 20:00:54 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 30 08:08:18 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Jan 30 08:08:20 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 30 08:08:20 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 30 08:08:20 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 08:08:20 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 30 08:08:20 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 08:08:20 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 30 08:08:20 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 08:08:20 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 08:08:20 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 30 08:08:21 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 08:08:21 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 30 08:08:21 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 30 08:08:21 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 08:08:21 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 30 08:08:21 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Jan 30 08:08:22 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0069.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 08:08:22 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 30 08:08:22 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 30 08:08:22 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 30 08:08:22 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 08:08:22 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 30 12:03:48 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Jan 30 12:03:48 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 30 12:03:48 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 30 12:03:48 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 12:03:48 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 30 12:03:48 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 12:03:48 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 30 12:03:48 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 12:03:48 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 12:03:48 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 30 12:03:48 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 12:03:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 30 12:03:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 30 12:03:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 12:03:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 30 12:03:49 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Jan 30 12:03:49 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0070.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 12:03:49 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 30 12:03:49 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 30 12:03:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 30 12:03:50 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 12:03:50 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 30 16:04:03 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Jan 30 16:04:03 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 30 16:04:03 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 30 16:04:03 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 16:04:03 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 30 16:04:03 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 16:04:03 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 30 16:04:03 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 16:04:03 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 16:04:03 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 30 16:04:03 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 16:04:03 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 30 16:04:03 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 30 16:04:03 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 16:04:03 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 30 16:04:03 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Jan 30 16:04:03 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0071.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 16:04:03 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 30 16:04:03 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 30 16:04:04 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 30 16:04:04 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 16:04:04 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0072.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Jan 30 20:02:08 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 31 08:07:41 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Jan 31 08:07:42 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 31 08:07:42 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 31 08:07:42 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 08:07:42 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 31 08:07:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 08:07:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 31 08:07:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 08:07:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 08:07:42 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 31 08:07:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 08:07:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 31 08:07:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 31 08:07:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 08:07:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 31 08:07:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Jan 31 08:07:43 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0073.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 08:07:43 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 31 08:07:43 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 31 08:07:44 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 31 08:07:44 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 08:07:44 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 31 12:04:10 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Jan 31 12:04:10 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 31 12:04:10 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 31 12:04:10 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 12:04:10 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 31 12:04:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 12:04:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 31 12:04:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 12:04:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 12:04:11 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 31 12:04:11 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 12:04:11 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 31 12:04:11 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 31 12:04:11 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 12:04:11 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 31 12:04:11 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Jan 31 12:04:11 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0074.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 12:04:11 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 31 12:04:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 31 12:04:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 31 12:04:11 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 12:04:11 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 31 16:02:12 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Jan 31 16:02:12 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 31 16:02:12 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 31 16:02:12 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 16:02:12 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 31 16:02:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 16:02:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 31 16:02:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 16:02:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 16:02:12 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 31 16:02:13 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 16:02:13 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 31 16:02:13 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 31 16:02:13 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 16:02:13 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 31 16:02:13 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Jan 31 16:02:13 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0075.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 16:02:13 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 31 16:02:13 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 31 16:02:13 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 31 16:02:13 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 16:02:13 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 31 20:01:03 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Jan 31 20:01:03 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 31 20:01:03 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 31 20:01:03 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 20:01:03 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 31 20:01:03 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 20:01:03 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 31 20:01:03 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 20:01:03 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 20:01:04 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 31 20:01:04 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 20:01:04 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 31 20:01:04 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 31 20:01:04 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 20:01:04 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Jan 31 20:01:04 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Jan 31 20:01:04 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0076.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 20:01:04 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Jan 31 20:01:04 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Jan 31 20:01:04 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Jan 31 20:01:04 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Jan 31 20:01:04 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 1 08:09:24 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Feb 1 08:09:24 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 1 08:09:24 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 1 08:09:24 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 08:09:24 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 1 08:09:24 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 08:09:24 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 1 08:09:24 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 08:09:24 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 08:09:24 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 1 08:09:25 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 08:09:25 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 1 08:09:25 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 1 08:09:25 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 08:09:25 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 1 08:09:25 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Feb 1 08:09:25 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0077.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 08:09:25 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 1 08:09:25 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 1 08:09:25 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 1 08:09:25 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 08:09:25 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0078.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 1 12:02:38 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 12:02:39 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 1 16:01:01 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Feb 1 16:01:01 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 1 16:01:01 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 1 16:01:01 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 16:01:01 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 1 16:01:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 16:01:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 1 16:01:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 16:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 16:01:02 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 1 16:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 16:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 1 16:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 1 16:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 16:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 1 16:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Feb 1 16:01:02 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0079.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 16:01:02 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 1 16:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 1 16:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 1 16:01:02 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 16:01:02 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 1 20:00:58 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0080.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 1 20:00:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 2 08:11:56 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Thu Feb 2 08:12:00 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 2 08:12:01 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 2 08:12:01 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 08:12:01 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 2 08:12:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 08:12:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 2 08:12:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 08:12:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 08:12:02 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 2 08:12:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 08:12:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 2 08:12:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 2 08:12:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 08:12:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 2 08:12:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Thu Feb 2 08:12:02 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0081.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 08:12:03 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 2 08:12:03 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 2 08:12:03 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 2 08:12:03 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 08:12:03 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 2 12:02:43 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Thu Feb 2 12:02:43 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0082.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 12:02:44 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0083.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 16:01:09 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 2 20:00:58 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Thu Feb 2 20:00:58 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 2 20:00:58 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 2 20:00:58 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 20:00:58 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 2 20:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 20:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 2 20:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 20:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 20:00:58 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 2 20:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 20:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 2 20:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 2 20:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 20:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 2 20:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Thu Feb 2 20:00:59 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0084.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 20:00:59 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 2 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 2 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 2 20:00:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 2 20:00:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 3 08:11:41 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Feb 3 08:11:42 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 3 08:11:42 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 3 08:11:42 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 08:11:42 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 3 08:11:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 08:11:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 3 08:11:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 08:11:42 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 08:11:43 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 3 08:11:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 08:11:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 3 08:11:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 3 08:11:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 08:11:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 3 08:11:43 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Feb 3 08:11:43 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0085.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 08:11:43 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 3 08:11:44 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 3 08:11:44 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 3 08:11:44 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 08:11:44 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 3 12:02:32 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Feb 3 12:02:32 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 3 12:02:32 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 3 12:02:32 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 12:02:32 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 3 12:02:32 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 12:02:32 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 3 12:02:32 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 12:02:32 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 12:02:32 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 3 12:02:32 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 12:02:32 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 3 12:02:32 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 3 12:02:32 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 12:02:32 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 3 12:02:32 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Feb 3 12:02:32 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0086.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 12:02:32 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 3 12:02:32 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 3 12:02:33 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 3 12:02:33 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 12:02:33 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0087.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 16:00:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 3 20:01:04 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Feb 3 20:01:04 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 3 20:01:04 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 3 20:01:04 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 20:01:04 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 3 20:01:04 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 20:01:04 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 3 20:01:04 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 20:01:04 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 20:01:04 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 3 20:01:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 20:01:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 3 20:01:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 3 20:01:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 20:01:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 3 20:01:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Feb 3 20:01:05 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0088.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 20:01:05 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 3 20:01:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 3 20:01:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 3 20:01:05 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 3 20:01:05 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 4 08:07:31 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Feb 4 08:07:32 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 4 08:07:32 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 4 08:07:32 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 08:07:32 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 4 08:07:32 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 08:07:32 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 4 08:07:32 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 08:07:32 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 08:07:33 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 4 08:07:33 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 08:07:33 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 4 08:07:33 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 4 08:07:33 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 08:07:33 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 4 08:07:33 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Feb 4 08:07:33 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0089.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 08:07:33 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 4 08:07:33 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 4 08:07:33 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 4 08:07:33 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 08:07:33 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 4 12:02:37 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Feb 4 12:02:37 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 4 12:02:37 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 4 12:02:37 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 12:02:37 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 4 12:02:37 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 12:02:37 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 4 12:02:37 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 12:02:37 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 12:02:37 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 4 12:02:37 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 12:02:37 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 4 12:02:37 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 4 12:02:38 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 12:02:38 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 4 12:02:38 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Feb 4 12:02:38 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0090.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 12:02:38 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 4 12:02:38 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 4 12:02:38 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 4 12:02:38 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 12:02:38 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 4 16:01:10 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Feb 4 16:01:10 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 4 16:01:10 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 4 16:01:11 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 16:01:11 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 4 16:01:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 16:01:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 4 16:01:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 16:01:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 16:01:11 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 4 16:01:11 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 16:01:11 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 4 16:01:11 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 4 16:01:11 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 16:01:11 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 4 16:01:11 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Feb 4 16:01:11 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0091.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 16:01:11 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 4 16:01:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 4 16:01:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 4 16:01:11 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 16:01:11 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0092.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 4 20:01:01 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 5 08:07:45 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Feb 5 08:07:46 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 5 08:07:46 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 5 08:07:46 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 08:07:46 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 5 08:07:46 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 08:07:46 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 5 08:07:46 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 08:07:46 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 08:07:46 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 5 08:07:46 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 08:07:46 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 5 08:07:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 5 08:07:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 08:07:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 5 08:07:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Feb 5 08:07:47 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0093.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 08:07:47 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 5 08:07:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 5 08:07:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 5 08:07:47 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 08:07:47 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0094.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 12:02:38 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0095.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 16:01:05 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 5 20:00:57 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Feb 5 20:00:57 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 5 20:00:57 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 5 20:00:57 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 20:00:57 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 5 20:00:57 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 20:00:57 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 5 20:00:57 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 20:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 20:00:58 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 5 20:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 20:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 5 20:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 5 20:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 20:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 5 20:00:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Feb 5 20:00:58 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0096.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 20:00:58 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 5 20:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 5 20:00:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 5 20:00:58 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 5 20:00:58 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 6 08:13:54 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Feb 6 08:13:56 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 6 08:13:56 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 6 08:13:56 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 08:13:57 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 6 08:13:57 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 08:13:57 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 6 08:13:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 08:13:58 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 08:13:58 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 6 08:13:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 08:13:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 6 08:13:58 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 6 08:13:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 08:13:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 6 08:13:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Feb 6 08:13:59 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0097.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 08:13:59 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 6 08:13:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 6 08:13:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 6 08:13:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 08:14:00 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 6 12:02:35 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Feb 6 12:02:35 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 6 12:02:35 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 6 12:02:35 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 12:02:35 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 6 12:02:35 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 12:02:35 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 6 12:02:35 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 12:02:35 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 12:02:35 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 6 12:02:35 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 12:02:35 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 6 12:02:35 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 6 12:02:35 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 12:02:35 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 6 12:02:35 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Feb 6 12:02:36 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0098.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 12:02:36 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 6 12:02:36 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 6 12:02:36 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 6 12:02:36 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 12:02:36 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0099.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 16:01:04 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 6 20:00:58 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Feb 6 20:00:58 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 6 20:00:58 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 6 20:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 20:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 6 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 6 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 20:00:59 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 6 20:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 20:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 6 20:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 6 20:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 20:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 6 20:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Feb 6 20:00:59 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0100.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 20:00:59 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 6 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 6 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 6 20:00:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 6 20:00:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 7 08:21:42 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Feb 7 08:21:44 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 7 08:21:44 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 7 08:21:44 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 08:21:44 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 7 08:21:44 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 08:21:44 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 7 08:21:45 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 08:21:45 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 08:21:45 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 7 08:21:45 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 08:21:45 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 7 08:21:46 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 7 08:21:46 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 08:21:46 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 7 08:21:47 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Feb 7 08:21:49 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0101.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 08:21:50 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 7 08:21:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 7 08:21:51 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 7 08:21:51 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 08:21:51 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 7 12:03:11 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Feb 7 12:03:11 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 7 12:03:11 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 7 12:03:11 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 12:03:11 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 7 12:03:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 12:03:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 7 12:03:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 12:03:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 12:03:12 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 7 12:03:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 12:03:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 7 12:03:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 7 12:03:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 12:03:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 7 12:03:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Feb 7 12:03:12 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0102.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 12:03:12 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 7 12:03:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 7 12:03:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 7 12:03:12 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 12:03:12 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0103.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 16:01:07 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0104.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 7 20:01:02 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 8 08:21:30 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Feb 8 08:21:33 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 8 08:21:33 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 8 08:21:34 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 08:21:34 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 8 08:21:34 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 08:21:34 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 8 08:21:34 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 08:21:34 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 08:21:35 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 8 08:21:35 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 08:21:35 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 8 08:21:35 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 8 08:21:36 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 08:21:36 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 8 08:21:37 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Feb 8 08:21:37 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0105.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 08:21:37 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 8 08:21:37 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 8 08:21:37 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 8 08:21:38 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 08:21:38 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 8 12:03:12 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Feb 8 12:03:13 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 8 12:03:13 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 8 12:03:13 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 12:03:13 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 8 12:03:13 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 12:03:13 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 8 12:03:13 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 12:03:13 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 12:03:13 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 8 12:03:13 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 12:03:13 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 8 12:03:13 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 8 12:03:13 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 12:03:13 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 8 12:03:13 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Feb 8 12:03:13 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0106.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 12:03:13 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 8 12:03:13 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 8 12:03:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 8 12:03:14 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 12:03:14 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 8 16:01:12 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Feb 8 16:01:12 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 8 16:01:12 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 8 16:01:12 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 16:01:12 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 8 16:01:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 16:01:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 8 16:01:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 16:01:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 16:01:12 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 8 16:01:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 16:01:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 8 16:01:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 8 16:01:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 16:01:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 8 16:01:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Feb 8 16:01:12 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0107.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 16:01:12 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 8 16:01:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 8 16:01:13 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 8 16:01:13 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 16:01:13 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 8 20:01:00 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Feb 8 20:01:00 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 8 20:01:00 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 8 20:01:00 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 20:01:00 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 8 20:01:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 20:01:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 8 20:01:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 20:01:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 20:01:01 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 8 20:01:01 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 20:01:01 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 8 20:01:01 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 8 20:01:01 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 20:01:01 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 8 20:01:01 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Feb 8 20:01:02 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0108.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 20:01:02 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 8 20:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 8 20:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 8 20:01:02 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 8 20:01:02 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 9 08:08:48 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Thu Feb 9 08:08:49 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 9 08:08:49 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 9 08:08:49 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 08:08:49 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 9 08:08:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 08:08:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 9 08:08:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 08:08:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 08:08:50 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 9 08:08:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 08:08:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 9 08:08:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 9 08:08:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 08:08:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 9 08:08:50 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Thu Feb 9 08:08:51 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0109.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 08:08:51 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 9 08:08:51 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 9 08:08:51 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 9 08:08:51 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 08:08:51 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 9 12:02:51 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Thu Feb 9 12:02:52 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 9 12:02:52 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 9 12:02:52 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 12:02:52 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 9 12:02:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 12:02:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 9 12:02:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 12:02:52 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 12:02:53 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 9 12:02:53 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 12:02:53 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 9 12:02:53 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 9 12:02:53 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 12:02:53 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 9 12:02:53 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Thu Feb 9 12:02:53 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0110.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 12:02:53 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 9 12:02:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 9 12:02:53 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 9 12:02:53 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 12:02:53 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0111.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 16:01:14 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 9 20:01:06 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Thu Feb 9 20:01:06 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 9 20:01:06 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 9 20:01:07 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 20:01:07 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 9 20:01:07 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 20:01:07 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 9 20:01:07 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 20:01:07 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 20:01:07 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 9 20:01:07 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 20:01:07 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 9 20:01:07 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 9 20:01:07 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 20:01:07 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 9 20:01:07 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Thu Feb 9 20:01:07 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0112.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 20:01:07 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 9 20:01:07 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 9 20:01:07 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 9 20:01:07 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 9 20:01:07 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 10 08:18:43 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Feb 10 08:18:45 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 10 08:18:45 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 10 08:18:47 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 08:18:47 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 10 08:18:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 08:18:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 10 08:18:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 08:18:47 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 08:18:47 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 10 08:18:48 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 08:18:48 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 10 08:18:48 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 10 08:18:48 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 08:18:48 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 10 08:18:48 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Feb 10 08:18:49 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0113.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 08:18:50 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 10 08:18:50 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 10 08:18:51 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 10 08:18:51 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 08:18:51 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0114.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 12:03:30 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0115.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 16:01:05 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0116.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Feb 10 20:01:11 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 11 08:12:33 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Feb 11 08:12:35 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 11 08:12:35 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 11 08:12:35 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 08:12:35 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 11 08:12:35 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 08:12:35 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 11 08:12:35 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 08:12:35 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 08:12:35 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 11 08:12:35 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 08:12:35 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 11 08:12:36 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 11 08:12:36 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 08:12:36 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 11 08:12:36 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Feb 11 08:12:36 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0117.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 08:12:36 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 11 08:12:36 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 11 08:12:36 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 11 08:12:36 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 08:12:36 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 11 12:02:31 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Feb 11 12:02:31 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 11 12:02:31 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 11 12:02:31 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 12:02:31 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 11 12:02:31 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 12:02:31 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 11 12:02:31 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 12:02:31 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 12:02:31 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 11 12:02:31 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 12:02:31 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 11 12:02:31 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 11 12:02:31 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 12:02:31 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 11 12:02:32 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Feb 11 12:02:32 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0118.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 12:02:32 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 11 12:02:32 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 11 12:02:32 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 11 12:02:32 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 12:02:32 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 11 16:01:02 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Feb 11 16:01:02 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 11 16:01:02 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 11 16:01:02 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 16:01:02 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 11 16:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 16:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 11 16:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 16:01:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 16:01:02 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 11 16:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 16:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 11 16:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 11 16:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 16:01:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 11 16:01:03 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Feb 11 16:01:03 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0119.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 16:01:03 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 11 16:01:03 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 11 16:01:03 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 11 16:01:03 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 16:01:03 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 11 20:00:55 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sat Feb 11 20:00:55 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 11 20:00:55 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 11 20:00:55 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 20:00:55 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 11 20:00:55 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 20:00:55 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 11 20:00:55 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 20:00:55 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 20:00:55 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 11 20:00:55 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 20:00:55 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 11 20:00:55 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 11 20:00:55 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 20:00:55 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sat Feb 11 20:00:55 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sat Feb 11 20:00:56 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0120.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 20:00:56 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sat Feb 11 20:00:56 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sat Feb 11 20:00:56 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sat Feb 11 20:00:56 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sat Feb 11 20:00:56 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 12 08:08:58 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Feb 12 08:08:59 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 12 08:08:59 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 12 08:08:59 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 08:08:59 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 12 08:08:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 08:08:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 12 08:08:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 08:08:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 08:08:59 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 12 08:08:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 08:09:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 12 08:09:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 12 08:09:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 08:09:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 12 08:09:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Feb 12 08:09:01 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0121.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 08:09:01 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 12 08:09:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 12 08:09:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 12 08:09:01 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 08:09:01 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 12 12:02:39 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Feb 12 12:02:40 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 12 12:02:40 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 12 12:02:40 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 12:02:40 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 12 12:02:40 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 12:02:40 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 12 12:02:40 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 12:02:40 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 12:02:40 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 12 12:02:40 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 12:02:40 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 12 12:02:40 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 12 12:02:40 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 12:02:41 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 12 12:02:41 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Feb 12 12:02:41 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0122.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 12:02:41 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 12 12:02:41 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 12 12:02:41 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 12 12:02:41 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 12:02:41 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 12 16:01:06 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0123.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 16:01:07 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0124.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun Feb 12 20:00:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 13 08:16:25 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Feb 13 08:16:27 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 13 08:16:27 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 13 08:16:27 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 08:16:27 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 13 08:16:27 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 08:16:27 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 13 08:16:28 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 08:16:28 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 08:16:28 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 13 08:16:28 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 08:16:28 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 13 08:16:28 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 13 08:16:28 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 08:16:28 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 13 08:16:28 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Feb 13 08:16:31 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0125.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 08:16:31 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 13 08:16:31 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 13 08:16:31 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 13 08:16:31 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 08:16:31 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 13 12:02:58 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Feb 13 12:02:58 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 13 12:02:58 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 13 12:02:58 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 12:02:58 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 13 12:02:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 12:02:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 13 12:02:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 12:02:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 12:02:59 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 13 12:02:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 12:02:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 13 12:02:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 13 12:02:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 12:02:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 13 12:02:59 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Feb 13 12:02:59 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0126.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 12:02:59 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 13 12:02:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 13 12:02:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 13 12:02:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 12:02:59 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 13 16:01:21 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Feb 13 16:01:21 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 13 16:01:21 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 13 16:01:21 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 16:01:21 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 13 16:01:21 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 16:01:22 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 13 16:01:22 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 16:01:22 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 16:01:22 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 13 16:01:22 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 16:01:22 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 13 16:01:22 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 13 16:01:22 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 16:01:22 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 13 16:01:22 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Feb 13 16:01:22 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0127.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 16:01:22 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 13 16:01:22 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 13 16:01:22 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 13 16:01:22 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 16:01:22 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 13 20:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Mon Feb 13 20:00:59 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 13 20:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 13 20:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 20:00:59 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 13 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 13 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 20:00:59 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 20:00:59 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 13 20:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 20:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 13 20:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 13 20:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 20:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Mon Feb 13 20:01:00 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Mon Feb 13 20:01:00 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0128.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 20:01:00 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Mon Feb 13 20:01:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon Feb 13 20:01:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Mon Feb 13 20:01:00 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon Feb 13 20:01:00 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 14 08:18:30 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Feb 14 08:18:31 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 14 08:18:31 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 14 08:18:31 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 08:18:31 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 14 08:18:31 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 08:18:31 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 14 08:18:31 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 08:18:31 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 08:18:31 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 14 08:18:31 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 08:18:31 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 14 08:18:31 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 14 08:18:31 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 08:18:32 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 14 08:18:32 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Feb 14 08:18:39 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0129.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 08:18:39 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 14 08:18:39 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 14 08:18:39 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 14 08:18:39 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 08:18:39 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 14 12:03:14 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Feb 14 12:03:14 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 14 12:03:14 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 14 12:03:14 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 12:03:14 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 14 12:03:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 12:03:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 14 12:03:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 12:03:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 12:03:14 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 14 12:03:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 12:03:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 14 12:03:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 14 12:03:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 12:03:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 14 12:03:14 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Feb 14 12:03:15 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0130.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 12:03:15 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 14 12:03:15 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 14 12:03:15 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 14 12:03:15 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 12:03:15 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0131.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 16:01:30 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 14 20:01:09 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Tue Feb 14 20:01:09 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 14 20:01:09 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 14 20:01:09 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 20:01:10 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 14 20:01:10 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 20:01:10 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 14 20:01:10 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 20:01:10 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 20:01:10 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 14 20:01:10 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 20:01:10 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 14 20:01:10 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 14 20:01:10 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 20:01:10 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Tue Feb 14 20:01:10 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Tue Feb 14 20:01:10 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0132.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 20:01:10 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Tue Feb 14 20:01:10 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Tue Feb 14 20:01:10 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Tue Feb 14 20:01:10 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue Feb 14 20:01:10 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 15 08:26:09 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Feb 15 08:26:13 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 15 08:26:13 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 15 08:26:13 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 08:26:14 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 15 08:26:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 08:26:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 15 08:26:14 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 08:26:15 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 08:26:15 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 15 08:26:15 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 08:26:15 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 15 08:26:15 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 15 08:26:15 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 08:26:16 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 15 08:26:16 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Feb 15 08:26:22 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0133.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 08:26:22 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 15 08:26:22 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 15 08:26:22 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 15 08:26:22 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 08:26:22 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 15 12:05:11 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Feb 15 12:05:11 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 15 12:05:11 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 15 12:05:11 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 12:05:11 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 15 12:05:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 12:05:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 15 12:05:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 12:05:11 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 12:05:11 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 15 12:05:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 12:05:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 15 12:05:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 15 12:05:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 12:05:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 15 12:05:12 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Feb 15 12:05:12 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0134.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 12:05:12 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 15 12:05:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 15 12:05:12 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 15 12:05:12 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 12:05:12 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0135.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 16:01:29 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 15 19:28:00 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Feb 15 19:28:00 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 15 19:28:00 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 15 19:28:00 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 19:28:00 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 15 19:28:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 19:28:00 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 15 19:28:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 19:28:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 19:28:01 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 15 19:28:01 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 19:28:01 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 15 19:28:01 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 15 19:28:01 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 19:28:01 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 15 19:28:01 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Feb 15 19:28:01 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0136.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 19:28:01 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 15 19:28:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 15 19:28:01 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 15 19:28:01 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 19:28:01 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 15 20:12:59 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Wed Feb 15 20:13:02 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 15 20:13:02 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 15 20:13:02 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 20:13:02 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 15 20:13:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 20:13:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 15 20:13:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 20:13:02 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 20:13:02 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 15 20:13:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 20:13:02 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 15 20:13:03 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 15 20:13:03 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 20:13:03 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Wed Feb 15 20:13:03 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Wed Feb 15 20:13:03 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0137.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 20:13:03 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Wed Feb 15 20:13:03 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Wed Feb 15 20:13:03 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Wed Feb 15 20:13:03 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed Feb 15 20:13:03 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 16 08:44:53 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Thu Feb 16 08:44:56 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 16 08:44:56 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 16 08:44:56 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 16 08:44:56 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 16 08:44:56 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 16 08:44:57 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 16 08:44:57 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 16 08:44:57 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 16 08:44:57 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 16 08:44:57 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 16 08:44:57 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 16 08:44:57 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 16 08:44:57 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 16 08:44:57 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Thu Feb 16 08:44:57 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Thu Feb 16 08:45:16 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0138.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 16 08:45:16 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Thu Feb 16 08:45:16 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Thu Feb 16 08:45:16 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Thu Feb 16 08:45:16 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu Feb 16 08:45:16 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From stuff at mailzilla.net Mon Aug 4 14:59:59 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Mar 31 16:33:30 2006 Subject: [egenix-users] column names ? In-Reply-To: <20030731120738.GA18162@foof.i3.cz> Message-ID: Is there a way, via mxODBC to obtain the column names for a particular query. For example, c = db.cursor() sql = "SELECT * FROM foo" c.execute(sql) I've tried c.columns() (before and after a fetchone()) but that always yields -1 (at least when connected to SQL Server). c.colcount seems to return the correct number of columns, so that could be useful. Is there a way to map the column name to a column number. That is, if I have a colcount of 10, how can I determine the name of column 4? I suspect the answer is "no" considering that the pretty_print mx.ODBC method seems to be unaware of the column names (at least according to the mxODBC examples on the web site). Thanks for any info, Phil From jgv-work at earthlink.net Mon Aug 4 17:03:42 2003 From: jgv-work at earthlink.net (j vickroy) Date: Fri Mar 31 16:33:30 2006 Subject: [egenix-users] column names ? References: Message-ID: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Hello Phil, After a query retrieval (e.g., cursor.fetchall()) look at the cursor.description attribute. In particular, element zero of each tuple, that is cursor.description, should contain the column name. ----- Original Message ----- From: To: Sent: Monday, 04 August, 2003 14:59 Subject: [egenix-users] column names ? > > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so that could be > useful. Is there a way to map the column name to a column number. That > is, if I have a colcount of 10, how can I determine the name of column 4? > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > method seems to be unaware of the column names (at least according to the > mxODBC examples on the web site). > > Thanks for any info, > > Phil > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users From stuff at mailzilla.net Mon Aug 4 16:10:08 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Mar 31 16:33:30 2006 Subject: [egenix-users] column names ? In-Reply-To: <006a01c35ad4$46a74600$7a4df4d1@QUESTAR> Message-ID: Thanks for the quick reply. That did the trick. Funny, I was printing the entire description tuple and missing the column name entirely and just assumed it wasn't in there. My bad. Thanks again, Phil On Mon, 4 Aug 2003, j vickroy wrote: > Hello Phil, > > After a query retrieval (e.g., cursor.fetchall()) look at the > cursor.description attribute. In particular, element zero of each tuple, > that is cursor.description, should contain the column name. > > > > ----- Original Message ----- > From: > To: > Sent: Monday, 04 August, 2003 14:59 > Subject: [egenix-users] column names ? > > > > > > Is there a way, via mxODBC to obtain the column names for a particular > > query. For example, > > > > c = db.cursor() > > > > sql = "SELECT * FROM foo" > > c.execute(sql) > > > > > > I've tried c.columns() (before and after a fetchone()) but that always > > yields -1 (at least when connected to SQL Server). > > > > c.colcount seems to return the correct number of columns, so that could be > > useful. Is there a way to map the column name to a column number. That > > is, if I have a colcount of 10, how can I determine the name of column 4? > > > > I suspect the answer is "no" considering that the pretty_print mx.ODBC > > method seems to be unaware of the column names (at least according to the > > mxODBC examples on the web site). > > > > Thanks for any info, > > > > Phil > > > > > > > > _______________________________________________________________________ > > eGenix.com User Mailing List http://www.egenix.com/ > > http://lists.egenix.com/mailman/listinfo/egenix-users > From sholden at holdenweb.com Mon Aug 4 19:31:50 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Mar 31 16:33:30 2006 Subject: [egenix-users] column names ? In-Reply-To: Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > stuff@mailzilla.net > Sent: Monday, August 04, 2003 5:00 PM > To: egenix-users@lists.egenix.com > Subject: [egenix-users] column names ? > > > > Is there a way, via mxODBC to obtain the column names for a > particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but > that always > yields -1 (at least when connected to SQL Server). > > c.colcount seems to return the correct number of columns, so > that could be > useful. Is there a way to map the column name to a column > number. That > is, if I have a colcount of 10, how can I determine the name > of column 4? > > I suspect the answer is "no" considering that the > pretty_print mx.ODBC > method seems to be unaware of the column names (at least > according to the > mxODBC examples on the web site). > > Thanks for any info, > You'll see how to do that if you take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 it uses the "description" attribute of the cursor. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Tue Aug 5 10:29:44 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Mar 31 16:33:30 2006 Subject: [egenix-users] column names ? In-Reply-To: References: Message-ID: <3F2F5CE8.9000906@lemburg.com> stuff@mailzilla.net wrote: > Is there a way, via mxODBC to obtain the column names for a particular > query. For example, > > c = db.cursor() > > sql = "SELECT * FROM foo" > c.execute(sql) > > > I've tried c.columns() (before and after a fetchone()) but that always > yields -1 (at least when connected to SQL Server). That's because .columns() generates a result set: c.columns(table="foo") print c.fetchall() -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 05 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From sholden at holdenweb.com Fri Aug 8 19:20:32 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Mar 31 16:33:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: I've found that a number of platforms (Access, MS SQL Server) don't appear to like the fractional seconds part of a DateTime. The resulting warning messages are a little tedious (though I realise I *could* suppress them with the warnings module). It's possible (though rather tedious) to reconstruct the object from its component attributes and truncate the seconds while so doing. I just wondered if anyone could think of a simpler way. I have this nagging feeling I'm overlooking the stunningly obvious. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From mal at lemburg.com Sat Aug 9 11:44:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Mar 31 16:33:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F34B484.8040404@lemburg.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. I'm not sure what you mean. If it's the warnings that you get in Python 2.3 from the time module functions if you pass in the .tuple() value due to mxDateTime representing the seconds as float, then this problem will be gone in 2.1.0 final (I decided to make seconds in the .tuple() output an integer; the float value is still available through the .seconds attribute). If you're talking about the str() representation which includes fractions, then the easiest way to get rid off the fractions is use .strftime() which doesn't handle fractions of a second by nature :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From wade at lightlink.com Sat Aug 9 09:24:03 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Mar 31 16:33:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds Message-ID: <200308090819.41574.wade@lightlink.com> Steve Holden wrote: > I've found that a number of platforms (Access, MS SQL Server) don't > appear to like the fractional seconds part of a DateTime. The resulting > warning messages are a little tedious (though I realise I *could* > suppress them with the warnings module). > > It's possible (though rather tedious) to reconstruct the object from its > component attributes and truncate the seconds while so doing. I just > wondered if anyone could think of a simpler way. I have this nagging > feeling I'm overlooking the stunningly obvious. On Win2K and SqlServer2000, I use int(myDateTimeObject) without problems: cursor.execute("insert into myTable (myDateTimeColumn) values (?)", (int(myDateTimeObject),)) Not *stunningly* obvious, but ... -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sat Aug 9 18:14:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Mar 31 16:33:30 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: References: Message-ID: <3F350FBD.5010900@lemburg.com> [put the list back on CC since I believe this is of interest to others as well] Steve Holden wrote: >>I'm not sure what you mean. If it's the warnings that you get in >>Python 2.3 from the time module functions if you pass in the >>.tuple() value due to mxDateTime representing the seconds as >>float, then this problem will be gone in 2.1.0 final (I decided >>to make seconds in the .tuple() output an integer; the float >>value is still available through the .seconds attribute). >> >>If you're talking about the str() representation which includes >>fractions, then the easiest way to get rid off the fractions >>is use .strftime() which doesn't handle fractions of a second >>by nature :-) > > I'm actually talking about using a DateTime object as a parameter for > inserting into an Access Date column, specifically in this case under > Python 2.2.x: Ah, ok. AFAIR, Access tells mxODBC to send the date as string and since mxDateTime instances generate seconds with fractions which Access doesn't support, you get the warning. This simple trick should work: def AccessDateTime(dt): # cut away the seconds fraction part return str(dt)[:-3] curs.execute(stmt, (AccessDateTime(now()),) > $ python > Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > [GCC 3.2 20020927 (prerelease)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>>>import mx.ODBC.Windows as db >>>>conn = db.connect("billing") >>>>curs = conn.cursor() >>>>from mx.DateTime import now, DateTime >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (now(), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > Access Driver]Fractional truncation (null)', 5696) > >>>>n = now() >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, > int(n.second)), )) > 1 > > Unfortunately I'd already tried Wade's int() trick on the whole date, > without success in Access, I'm afraid, so it's interesting to know it > works with MS SQL Server: > > >>>>curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, > > Started)" > ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > 125.0, ?)", > ... (int(n), )) > Traceback (most recent call last): > File "", line 3, in ? > mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft > Access Driver]Numeric value out of range (null)', 5696) > > Maybe the DateTime.__int__() method could be defined in some helpful way > here? int(datetime) returns the Unix ticks value for the datetime you pass in. It is not meant to be used in this context. The idea is that you can pass DateTime instances to other functions which expect a Unix ticks integer. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal at lemburg.com Sun Aug 10 00:27:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Mar 31 16:33:30 2006 Subject: [egenix-users] eGenix mx Extensions for Python 2.3 (pre-release) Message-ID: <3F356731.3030509@lemburg.com> Hi everybody, eGenix is releasing updated versions of the eGenix mx Extensions for Python 2.3 next week. As special bonus we are releasing them here a few days before the final announcement. Please note that we have only upgraded parts from the current versions that needed tweaking for compilation under Python 2.3, so you basically only need to upgrade if you are focussing on Python 2.3 (which you should since it is much faster than all previous Python versions). We've also upgraded the egenix-mx-base-2.1.0 source code snapshot so that it properly compiles on Windows with Python 2.3: http://www.egenix.com/files/python/egenix-mx-base-2.1.0-2003-08-09.zip Here are the download links for the upgraded 2.0.x versions (supporting 5 different Python versions is starting to become a rather verbose task :-): http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-base-2.0.5.tar.gz http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-base-2.0.5.zip http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.tar.gz http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-commercial-2.0.6.zip http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py1.5_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.0_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.1_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.2_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-py2.3_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.i386.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0-pydev_1.src.rpm http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.tar.gz http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py1.5.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.0.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.1.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.2.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.win32-py2.3.exe http://www.egenix.com/files/python/egenix-mx-experimental-0.8.0.zip Enjoy ! -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 09 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:38:00 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Mar 31 16:33:31 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary Message-ID: <1060508280.24083.67.camel@jerry.westrick.local> Hello: I'm not sure if this is the right list, if not sorry. I'm trying to convert the result of a Zql method into a dictionary. the code I'm using is: # Get User Info for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): values['user'] = row The Get_UserInfo is a Z SQL Method, returning a single row from a mxODBC conneciton. when I executed the following lines: print values['user'] return printed I get I would to convert this r instance to a dictionary, so I can add/modify values in it like the following: values['user']['justforfun'] = 'Additional info not from select!' which at the moment gives me: Error Type: TypeError Error Value: object does not support item or slice assignment Now to my questions: 1) the class "r", is it a Zope thingy or a mxODBC thingy? 2) is there a mothod to do what I need? Than you for your time... Jerry P.S. There are other dictionary functions not support by this "R" instance that I would like to use also... From mal at lemburg.com Sun Aug 10 12:49:05 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Mar 31 16:33:31 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F361511.4090700@lemburg.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? It's a Zope thingy. mxODBC wraps the results as Zope Results instance which in return dynamically wraps rows as "r" instances which are subclasses of the Zope Record type. See lib/python/Shared/DC/ZRDB/Results.py for details. > 2) is there a mothod to do what I need? You should probably convert the r instance to a dictionary and then use that. The r instance does not support the full dictionary interface. In any case, the zope-db mailing list will probably give you better help. > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 12:54:16 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Mar 31 16:33:31 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F361511.4090700@lemburg.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F361511.4090700@lemburg.com> Message-ID: <1060509256.24082.74.camel@jerry.westrick.local> WOW! Thanks for the prompt responce! I'll repost to the Zope.... Jerry On Sun, 2003-08-10 at 11:49, M.-A. Lemburg wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > It's a Zope thingy. mxODBC wraps the results as Zope Results > instance which in return dynamically wraps rows as "r" instances > which are subclasses of the Zope Record type. > > See lib/python/Shared/DC/ZRDB/Results.py for details. > > > 2) is there a mothod to do what I need? > > You should probably convert the r instance to a dictionary > and then use that. The r instance does not support the > full dictionary interface. > > In any case, the zope-db mailing list will probably give you > better help. > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... From wade at lightlink.com Sun Aug 10 08:27:52 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Mar 31 16:33:31 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <1060508280.24083.67.camel@jerry.westrick.local> References: <1060508280.24083.67.camel@jerry.westrick.local> Message-ID: <3F362C38.2050203@lightlink.com> Jerry Westrick wrote: > Hello: > > I'm not sure if this is the right list, if not sorry. > > I'm trying to convert the result of a Zql method into a dictionary. > the code I'm using is: > > # Get User Info > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > values['user'] = row > > The Get_UserInfo is a Z SQL Method, returning a single row > from a mxODBC conneciton. > > when I executed the following lines: > > print values['user'] > return printed > > > I get > > > > I would to convert this r instance to a dictionary, so I can add/modify > values in it like the following: > > values['user']['justforfun'] = 'Additional info not from select!' > > which at the moment gives me: > > Error Type: TypeError > Error Value: object does not support item or slice assignment > > > > Now to my questions: > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > 2) is there a mothod to do what I need? > > > Than you for your time... > Jerry > > P.S. There are other dictionary functions not support by this "R" > instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple in a zsql result to a dictionary. But looking at the current docs http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx toward the bottom of the page, I see that zsql results have a dictionaries() method that returns a list of dicts. I wonder if that's a recent addition, or if I just never noticed it before? If that does not work for you, try this: def row2dict(row, names): D = {} for i in range(len(names)): D[names[i]] = row[i] return D result = context.somezsqlmethod() for row in result: print row2dict(row, result.names()) -- Wade Leftwich Ithaca, NY From mal at lemburg.com Sun Aug 10 14:52:33 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Mar 31 16:33:31 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <3F363201.4050603@lemburg.com> Wade Leftwich wrote: >> Now to my questions: >> 1) the class "r", is it a Zope thingy or a mxODBC thingy? >> 2) is there a mothod to do what I need? >> >> >> Than you for your time... >> Jerry >> >> P.S. There are other dictionary functions not support by this "R" >> instance that I would like to use also... > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? It's been in Zope for quite a while (and I must have forgotten all about it too :-). It gives you a list of dictionaries, one for each row, mapping column names to values. > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) That's pretty much what result.dictionaries() does for the complete result set :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 10 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From Jerry at Westrick.Com Sun Aug 10 14:39:58 2003 From: Jerry at Westrick.Com (Jerry Westrick) Date: Fri Mar 31 16:33:31 2006 Subject: [egenix-users] Converting ZQL method return value to dictionary In-Reply-To: <3F362C38.2050203@lightlink.com> References: <1060508280.24083.67.camel@jerry.westrick.local> <3F362C38.2050203@lightlink.com> Message-ID: <1060515598.24083.78.camel@jerry.westrick.local> Hello Wade... Thank you, got it... My problem was realizing that the "result set" has a .dictionaries() and not the resulting records defined within the result set... Don't ask me why, but hey... SO the dictionaries() works outside of the for loop! Thanks for your help! Jerry On Sun, 2003-08-10 at 13:27, Wade Leftwich wrote: > Jerry Westrick wrote: > > Hello: > > > > I'm not sure if this is the right list, if not sorry. > > > > I'm trying to convert the result of a Zql method into a dictionary. > > the code I'm using is: > > > > # Get User Info > > for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER): > > values['user'] = row > > > > The Get_UserInfo is a Z SQL Method, returning a single row > > from a mxODBC conneciton. > > > > when I executed the following lines: > > > > print values['user'] > > return printed > > > > > > I get > > > > > > > > I would to convert this r instance to a dictionary, so I can add/modify > > values in it like the following: > > > > values['user']['justforfun'] = 'Additional info not from select!' > > > > which at the moment gives me: > > > > Error Type: TypeError > > Error Value: object does not support item or slice assignment > > > > > > > > Now to my questions: > > 1) the class "r", is it a Zope thingy or a mxODBC thingy? > > 2) is there a mothod to do what I need? > > > > > > Than you for your time... > > Jerry > > > > P.S. There are other dictionary functions not support by this "R" > > instance that I would like to use also... > > > > > > In the past I have frequently written a function to convert each tuple > in a zsql result to a dictionary. But looking at the current docs > > http://zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases.stx > > toward the bottom of the page, I see that zsql results have a > dictionaries() method that returns a list of dicts. I wonder if that's a > recent addition, or if I just never noticed it before? > > If that does not work for you, try this: > > def row2dict(row, names): > D = {} > for i in range(len(names)): > D[names[i]] = row[i] > return D > > result = context.somezsqlmethod() > for row in result: > print row2dict(row, result.names()) > > > -- Wade Leftwich > Ithaca, NY > > > > > > > > > > _______________________________________________________________________ > eGenix.com User Mailing List http://www.egenix.com/ > http://lists.egenix.com/mailman/listinfo/egenix-users > From sabaini at telbiomed.at Mon Aug 18 18:16:45 2003 From: sabaini at telbiomed.at (Peter Sabaini) Date: Fri Mar 31 16:33:31 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures Message-ID: <3F40EDDD.5080407@telbiomed.at> Hello list, I am getting strange exceptions when using the mxODBC Zope DA: """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt""" (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist mit Ergebnissen von einem anderen hstmt belegt""") The exception only occurs under load. Has anyone else seen this? I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 and MDAC 2.8; our application relies heavily on stored procedures, and I turned on the "Fetch last available result set" option. The "mxODBC Interface Documentation" mentions some issues with MS SQL and recommends forcing the usage of server side cursors via the setconnectoption() method of the database connection. How do I do this with the Zope DA? As far as I can tell, the Zope "Database Connection" has an attribute 'connection', which features a setconnectoption() method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that didn't help, ie. the exception still occurs. Thank you, peter sabaini. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4700 bytes Desc: S/MIME Cryptographic Signature Url : /mailman-archives/egenix-users/attachments/20030818/d587e0b2/smime-0139.bin From mal at lemburg.com Mon Aug 18 21:40:52 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Mar 31 16:33:31 2006 Subject: [egenix-users] Exceptions with MS SQL, Stored Procedures In-Reply-To: <3F40EDDD.5080407@telbiomed.at> References: <3F40EDDD.5080407@telbiomed.at> Message-ID: <3F411DB4.8040207@lemburg.com> Peter Sabaini wrote: > Hello list, > > > I am getting strange exceptions when using the mxODBC Zope DA: > > """HY000 [Microsoft][ODBC SQL Server Driver]Connection is busy with > results for another hstmt""" > > (german: """HY000 [Microsoft][ODBC SQL Server Driver]Die Verbindung ist > mit Ergebnissen von einem anderen hstmt belegt""") > > > The exception only occurs under load. > > Has anyone else seen this? > > I'm using Zope 2.6.1 / win32, Python 2.1.3 with MS SQL Server 8.00.194 > and MDAC 2.8; our application relies heavily on stored procedures, and I > turned on the "Fetch last available result set" option. Here's a MS article on the topic: http://support.microsoft.com/default.aspx?scid=%2Fservicedesks%2Fbin%2Fkbsearch.asp%3FArticle%3D253010 They say it was corrected in MDAC 2.6... Another reference mentions it as limitation in MS SQL Server ODBC driver: http://www.588188.com/netbook/sqlserver2000/odbcsql/od_6_030_5337.htm The problem only occurs if you have multiple result sets open, e.g. from a stored procedure call. The only true fix seems to be to have the stored procedures close the result sets (that are not needed) before returning the final result set or to use an ODBC driver from one of the other ODBC driver vendors which don't have this limitation. > The "mxODBC Interface Documentation" mentions some issues with MS SQL > and recommends forcing the usage of server side cursors via the > setconnectoption() method of the database connection. How do I do this > with the Zope DA? As far as I can tell, the Zope "Database Connection" > has an attribute 'connection', which features a setconnectoption() > method. I tried to set the CURSOR_TYPE to CURSOR_DYNAMIC, but that > didn't help, ie. the exception still occurs. Setting these low-level connection options is currently not advisable on DatabaseConnections because these are pooled, so tweaking one connection will not reach out to other connections and as a result you'll get strange effects and unreliable connections. You could, however, experiment with this if you set the pool size to 1 and only have one Zope connection object in your ZODB. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 18 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From wade at lightlink.com Tue Aug 19 15:26:22 2003 From: wade at lightlink.com (Wade Leftwich) Date: Fri Mar 31 16:33:31 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F350FBD.5010900@lemburg.com> References: <3F350FBD.5010900@lemburg.com> Message-ID: <3F426BCE.70807@lightlink.com> M.-A. Lemburg wrote: > [put the list back on CC since I believe this is of interest > to others as well] > > Steve Holden wrote: > >>> I'm not sure what you mean. If it's the warnings that you get in >>> Python 2.3 from the time module functions if you pass in the >>> .tuple() value due to mxDateTime representing the seconds as >>> float, then this problem will be gone in 2.1.0 final (I decided >>> to make seconds in the .tuple() output an integer; the float >>> value is still available through the .seconds attribute). >>> >>> If you're talking about the str() representation which includes >>> fractions, then the easiest way to get rid off the fractions >>> is use .strftime() which doesn't handle fractions of a second >>> by nature :-) >> >> >> I'm actually talking about using a DateTime object as a parameter for >> inserting into an Access Date column, specifically in this case under >> Python 2.2.x: > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > and since mxDateTime instances generate seconds with fractions > which Access doesn't support, you get the warning. > > This simple trick should work: > > def AccessDateTime(dt): > # cut away the seconds fraction part > return str(dt)[:-3] > curs.execute(stmt, (AccessDateTime(now()),) > >> $ python >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) >> [GCC 3.2 20020927 (prerelease)] on cygwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import mx.ODBC.Windows as db >>>>> conn = db.connect("billing") >>>>> curs = conn.cursor() >>>>> from mx.DateTime import now, DateTime >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (now(), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft >> Access Driver]Fractional truncation (null)', 5696) >> >>>>> n = now() >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (DateTime(n.year, n.month, n.day, n.hour, n.minute, >> int(n.second)), )) >> 1 >> >> Unfortunately I'd already tried Wade's int() trick on the whole date, >> without success in Access, I'm afraid, so it's interesting to know it >> works with MS SQL Server: >> >> >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, Description, Rate, >> >> >> Started)" >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', >> 125.0, ?)", >> ... (int(n), )) >> Traceback (most recent call last): >> File "", line 3, in ? >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC Microsoft >> Access Driver]Numeric value out of range (null)', 5696) >> >> Maybe the DateTime.__int__() method could be defined in some helpful way >> here? > > > int(datetime) returns the Unix ticks value for the datetime > you pass in. It is not meant to be used in this context. > The idea is that you can pass DateTime instances to other > functions which expect a Unix ticks integer. > In case there is still interest in this topic, I ran into the same situation this afternoon, and did it this way: >>> from mx import DateTime >>> def truncFractionalSeconds(dt): ... """mxDateTime object => same with fractions of secs removed""" ... return DateTime.DateTimeFromTicks(int(dt)) ... >>> now = DateTime.now() >>> now >>> truncFractionalSeconds(now) >>> Seems to me like it's safer to pass your cursor a DateTime object than a string, which might lead to cross-platform problems. -- Wade Leftwich Ithaca, NY From sholden at holdenweb.com Fri Aug 22 11:32:12 2003 From: sholden at holdenweb.com (Steve Holden) Date: Fri Mar 31 16:33:31 2006 Subject: [egenix-users] mx.DateTime: Truncating fractional seconds In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: > -----Original Message----- > From: egenix-users-bounces@lists.egenix.com > [mailto:egenix-users-bounces@lists.egenix.com]On Behalf Of > Wade Leftwich > Sent: Tuesday, August 19, 2003 2:26 PM > To: sholden@holdenweb.com > Cc: eGenix.com User Mailinglist > Subject: Re: [egenix-users] mx.DateTime: Truncating fractional seconds > > > M.-A. Lemburg wrote: > > [put the list back on CC since I believe this is of interest > > to others as well] > > > > Steve Holden wrote: > > > >>> I'm not sure what you mean. If it's the warnings that you get in > >>> Python 2.3 from the time module functions if you pass in the > >>> .tuple() value due to mxDateTime representing the seconds as > >>> float, then this problem will be gone in 2.1.0 final (I decided > >>> to make seconds in the .tuple() output an integer; the float > >>> value is still available through the .seconds attribute). > >>> > >>> If you're talking about the str() representation which includes > >>> fractions, then the easiest way to get rid off the fractions > >>> is use .strftime() which doesn't handle fractions of a second > >>> by nature :-) > >> > >> > >> I'm actually talking about using a DateTime object as a > parameter for > >> inserting into an Access Date column, specifically in this > case under > >> Python 2.2.x: > > > > > > Ah, ok. AFAIR, Access tells mxODBC to send the date as string > > and since mxDateTime instances generate seconds with fractions > > which Access doesn't support, you get the warning. > > > > This simple trick should work: > > > > def AccessDateTime(dt): > > # cut away the seconds fraction part > > return str(dt)[:-3] > > curs.execute(stmt, (AccessDateTime(now()),) > > > >> $ python > >> Python 2.2.3 (#1, Jun 19 2003, 12:10:13) > >> [GCC 3.2 20020927 (prerelease)] on cygwin > >> Type "help", "copyright", "credits" or "license" for more > information. > >> > >>>>> import mx.ODBC.Windows as db > >>>>> conn = db.connect("billing") > >>>>> curs = conn.cursor() > >>>>> from mx.DateTime import now, DateTime > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (now(), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.Warning: ('01S07', 13, '[Microsoft][ODBC Microsoft > >> Access Driver]Fractional truncation (null)', 5696) > >> > >>>>> n = now() > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (DateTime(n.year, n.month, n.day, n.hour, > n.minute, > >> int(n.second)), )) > >> 1 > >> > >> Unfortunately I'd already tried Wade's int() trick on the > whole date, > >> without success in Access, I'm afraid, so it's interesting > to know it > >> works with MS SQL Server: > >> > >> > >>>>> curs.execute("INSERT INTO Task (pjName, TaskName, > Description, Rate, > >> > >> > >> Started)" > >> ... " VALUES('gpcc', 'TEST', 'Delete me after this!', > >> 125.0, ?)", > >> ... (int(n), )) > >> Traceback (most recent call last): > >> File "", line 3, in ? > >> mx.ODBC.Windows.DataError: ('22003', 34, '[Microsoft][ODBC > Microsoft > >> Access Driver]Numeric value out of range (null)', 5696) > >> > >> Maybe the DateTime.__int__() method could be defined in > some helpful way > >> here? > > > > > > int(datetime) returns the Unix ticks value for the datetime > > you pass in. It is not meant to be used in this context. > > The idea is that you can pass DateTime instances to other > > functions which expect a Unix ticks integer. > > > > In case there is still interest in this topic, I ran into the same > situation this afternoon, and did it this way: > > >>> from mx import DateTime > >>> def truncFractionalSeconds(dt): > ... """mxDateTime object => same with fractions of secs removed""" > ... return DateTime.DateTimeFromTicks(int(dt)) > ... > >>> now = DateTime.now() > >>> now > > >>> truncFractionalSeconds(now) > > >>> > > Seems to me like it's safer to pass your cursor a DateTime > object than a > string, which might lead to cross-platform problems. > You're quite right, Wade. Coo, wish *i* had a brain ... Seriously, I'll change the code to do it this wayt, it seems much saner to use methods than external procedures. regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From stuff at mailzilla.net Tue Aug 26 11:49:57 2003 From: stuff at mailzilla.net (stuff@mailzilla.net) Date: Fri Mar 31 16:33:31 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: <3F426BCE.70807@lightlink.com> Message-ID: Is there an mx.ODBC.Windows (or alternative Python) method to obtain a list of installed ODBC drivers on a Windows systems? The DataSources() is somewhat useful for connecting to previously defined ODBC sources, but if a source is yet to be defined, there won't be an entry here, even if the driver is installed. The Windows ODBC Data Source Admin Tool provides a list of drivers (on the "Drivers" tab), I just don't know how to get this information from Python. Thanks, Phil From mal at lemburg.com Tue Aug 26 22:35:28 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri Mar 31 16:33:31 2006 Subject: [egenix-users] Windows ODBC drivers? In-Reply-To: References: Message-ID: <3F4BB680.9090807@lemburg.com> stuff@mailzilla.net wrote: > Is there an mx.ODBC.Windows (or alternative Python) method to obtain a > list of installed ODBC drivers on a Windows systems? The DataSources() > is somewhat useful for connecting to previously defined ODBC sources, but > if a source is yet to be defined, there won't be an entry here, even if > the driver is installed. > > The Windows ODBC Data Source Admin Tool provides a list of drivers (on the > "Drivers" tab), I just don't know how to get this information from Python. There is an ODBC API for this, but it's currently not exposed via mxODBC. I suppose you could use the Python tools for querying the registry to find out about installed drivers. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2003-08-12: Released eGenix mx Extensions for Python 2.3 ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::